﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static WinFormsApp1.SuYi.Week2WinForm.WaitingWinFormShow;
using WinFormsApp1.Common;
using FastReport.DevComponents.DotNetBar.Controls;

namespace WinFormsApp1.WangHaoQi.Week02Winfroms
{
    public partial class SlaughterWinFormShow : Form
    {
        public SlaughterWinFormShow()
        {
            InitializeComponent();
            GetSlaughterShow();
        }

        /// <summary>
        /// 选择活畜
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton4_Click(object sender, EventArgs e)
        {
            LiveAnimalsShowHtml liveAnimalsShowHtml = new LiveAnimalsShowHtml();
            liveAnimalsShowHtml.ShowDialog();
        }
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton5_Click(object sender, EventArgs e)
        {
            SlaughterWinFormAdd slaughterWinFormAdd = new SlaughterWinFormAdd();
            slaughterWinFormAdd.ShowDialog();
        }

        private async void uiDataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

            


        }
        private int PageIndex = 1;
        private int PageSize = 3;
        public int totalPage = 0;
        public int totalCount = 0;
        public string SlaughterDocument = "";

        public async void GetSlaughterShow()
        {
            uiDataGridView1.AutoGenerateColumns = false;
            var pageDto = new PageDto()
            {
                PageIndex = PageIndex,
                PageSize = PageSize,
                SlaughterDocument = SlaughterDocument
            };

            var item = await HttpClientHelper.RequestUrl<object, ApiResultFY2<List<SlaughterDto>>>(URLCommon.Url2, "/Killplans/SlaughterShow", HttpClientHelper.MethodType.POST, pageDto);

            this.uiDataGridView1.DataSource = item.Data.list;
            totalCount = item.Data.totalCount;
            totalPage = item.Data.totalPage;

            //分页文字显示
            label5.Text = Convert.ToString(totalPage);
            label8.Text = Convert.ToString(totalCount);
            label11.Text = Convert.ToString(PageIndex);
            label14.Text = Convert.ToString(PageSize);

            //分页  页数的下拉框绑定
            List<object> list = new List<object>();
            for (var i = 1; i <= totalPage; i++)
            {
                list.Add(i);
            }
            comboBox4.DataSource = list;
            this.Controls.Add(comboBox4);
        }


        public class PageDto
        {
            /// <summary>
            /// 单据号
            /// </summary>
            public string? SlaughterDocument { get; set; }
            /// <summary>
            /// 页码
            /// </summary>
            public int PageIndex { get; set; }
            /// <summary>
            /// 条数
            /// </summary>
            public int PageSize { get; set; }
        }

        /// <summary>
        /// 批宰计划字段
        /// </summary>
        public class SlaughterDto
        {
            /// <summary>
            /// 计划屠宰日期 
            /// </summary>
            public DateTime? SlaughterDate { get; set; }
            /// <summary>
            /// 送宰类型
            /// </summary>
            public int SlaughterType { get; set; }
            /// <summary>
            /// 屠宰类型
            /// </summary>
            public int SlaughterMaxType { get; set; }
            /// <summary>
            /// 屠宰编号
            /// </summary>
            public string SlaughterNo { get; set; }

            /// <summary>
            /// 计划屠宰头数
            /// </summary>
            public int SlaughterNum { get; set; }
            /// <summary>
            /// 计划时间 大概需要多长时间
            /// </summary>
            public string ProjectDateTime { get; set; }
            /// <summary>
            /// 静养时间
            /// </summary>
            public string Resttime { get; set; }
            /// <summary>
            /// 备注
            /// </summary>
            public string SlaughterRemark { get; set; }

            /// <summary>
            /// 进场登记编号
            /// </summary>
            public string CheckInNo { get; set; }
            /// <summary>
            /// 进场批次
            /// </summary>
            public string CheckInBatch { get; set; }
            /// <summary>
            /// 商品代号名称
            /// </summary>
            public string UPCDataName { get; set; }
        }

        private void uiButton1_Click(object sender, EventArgs e)
        {
            SlaughterDocument = uiTextBox1.Text;
            GetSlaughterShow();
        }
        /// <summary>
        /// 首页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton8_Click(object sender, EventArgs e)
        {
            PageIndex = 1;
            GetSlaughterShow();
        }
        /// <summary>
        /// 上一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton9_Click(object sender, EventArgs e)
        {
            if (PageIndex > 1)
            {
                PageIndex--;

            }
            else
            {
                //弹框提示
                MessageBox.Show("已经第一页了");
            }
            GetSlaughterShow();
        }
        /// <summary>
        /// 下一页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton6_Click(object sender, EventArgs e)
        {
            if (PageIndex < totalPage)
            {
                PageIndex++;

            }
            else
            {
                //弹框提示
                MessageBox.Show("已经最后一页了");
            }
            GetSlaughterShow();
        }
        /// <summary>
        /// 尾页
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void uiButton7_Click(object sender, EventArgs e)
        {
            PageIndex = totalPage;
            GetSlaughterShow();
        }
    }
}
